<?php
/**
 * 地区管理控制器
 * 
 * @author sandy 
 */
class regionApp extends adminControl {

	public function index() {
		$region_mod = &get_model("region");
		
		// 获取当前页码及分页配置
		$page_info = get_page(20);
		
		$regions = $region_mod->get_children_region($page_info);
		
		// 获取分页信息
		$page_info['total'] = $regions['total'];
		$url = "index.php?c=region";
		$pages_data = format_page($page_info['total'], $page_info['cur_page'], $url, $page_info['per_page'],5);
		$pages = get_page_html($pages_data);
		
		$this->assign('regions', $regions['result']);
		$this->assign('pages',$pages);
		$this->display();
	}
	
	public function add() {
		
		$parent_id = isset ($_GET['rid']) ? intval($_GET['rid']) : 0;
		$dosubmit = isset($_REQUEST['dosubmit']) ? $_REQUEST['dosubmit'] : false;
		
		if ($dosubmit) {
			dump($_POST['region']);
		} else {
			
			if ($parent_id) {
				$region_mod = &get_model("region");
				$parent_info = $region_mod->get_region($parent_id);
				$this->assign('parent_info', $parent_info);
			}
			$this->display();
			
		}
	}
	
	public function edit () {
		$region_id = isset ($_GET['rid']) ? intval($_GET['rid']) : 0;
		$dosubmit = isset($_REQUEST['dosubmit']) ? $_REQUEST['dosubmit'] : false;
		
		$region_mod = &get_model("region");
			
		if ($dosubmit) {
			$region = isset ($_POST['region']) ? $_POST['region'] : 0;
			
			if ( $region_mod->update_region($region) ) {
				$this->show_message( "信息已经更新",$this->config->get_item('site_url').'/index.php?c=region');
			} else {
				$this->show_message( "保存编辑信息失败",$this->config->get_item('site_url').'/index.php?c=region&a=edit&rid='.$region_id);
			}
			
		} else {
			
			$region = $region_mod->get_region($region_id);
			
			if ($region['region_parent_id'] > 0) {
				$parent_info = $region_mod->get_region($parent_id);
				$this->assign('parent_info', $parent_info);
			}
			
			$this->assign('region', $region);
			$this->display();
		}
	}
	
	public function del () {
		$this->show_message( "功能开发中!",$this->config->get_item('site_url').'/index.php?c=region');
	}

}
